{include file="common/header"}
<link href="/static/admin/js/jquery-tags-input/jquery.tagsinput.min.css" rel="stylesheet">
<link href="/static/admin/css/other.css" rel="stylesheet">
<main class="lyear-layout-content">
    <div class="container-fluid">
        <div class="row ant-menu-submenu">
            <div class="col-lg-10 col-b90">
                <div class="card">
                    <div class="right-card-header card-header">
                        <h4>{$option_list['type']['type_name']}</h4>
                    </div>
                    <div class="card-body">
                        <div class="example-box set_attachment" id="myform">
                        {:options_generate($option_list['lists'])}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>
{include file="common/footer"}
<script type="text/javascript" src="/static/admin/js/set.js"></script>
<script src="/static/admin/js/jquery-tags-input/jquery.tagsinput.min.js"></script>
<script>
    let IM_config = {
        updateOptions: "{:adminUrl('admin/Set/update_options')}",
    };

    $(function () {
        $('#myform .options-open').click(function () {
            var obj = $(this);
            ajaxOptions({
                opid: obj.attr('data-id'),
                keys: obj.attr('name'),
                vals: obj.is(":checked")?1:0
            });
        });
        $('#myform .options-radio').click(function () {
            var obj = $(this);
            ajaxOptions({
                opid: obj.attr('data-id'),
                keys: obj.attr('name'),
                vals: obj.val()
            });
        });
        $('#myform .options-tags').click(function () {
            var obj = $(this);
            ajaxOptions({
                opid: obj.attr('data-id'),
                keys: obj.attr('name'),
                vals: obj.val()
            });
        });

        $('.options-tags').tagsInput({
            width:'auto',
            height:'36',
            defaultText: '添加',
            onAddTag:function() {
                var obj = $(this);
                ajaxOptions({
                    opid: obj.attr('data-id'),
                    keys: obj.attr('name'),
                    vals: obj.val()
                });
            },
            onRemoveTag:function() {
                var obj = $(this);
                ajaxOptions({
                    opid: obj.attr('data-id'),
                    keys: obj.attr('name'),
                    vals: obj.val()
                });
            }
        });
    });

    function ajaxOptions(data) {
        $.ajax({
            type: "post",
            url: IM_config.updateOptions,
            data: data,
            dataType: "json",
            success : function(r) {
                we_im_msg(r.data);
            }
        });
    }
</script>